package com.sky.service.impl;

import com.sky.constant.MessageConstant;
import com.sky.entity.Dish;
import com.sky.entity.Setmeal;
import com.sky.exception.BaseException;
import com.sky.mapper.DishMapper;
import com.sky.mapper.SetmealDishMapper;
import com.sky.mapper.UserSetmealMapper;
import com.sky.service.UserSetmealService;
import com.sky.vo.DishItemVO;
import com.sky.vo.SetmealVO;
import org.springframework.beans.BeanUtils;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * @author zcf
 */
@Service
public class UserSetmealServiceImpl implements UserSetmealService {

    @Resource
    private UserSetmealMapper userSetmealMapper;

    @Resource
    private DishMapper dishMapper;
    /**
     * 根据分类id查询套餐
     *
     * @param categoryId
     * @return
     */
    @Cacheable(cacheNames = "setmeal:cache",key = "#a0")
    @Override
    public List<Setmeal> list(Long categoryId) {
        List<Setmeal> list = userSetmealMapper.getByID(categoryId);
        if (list == null && list.size() == 0) {
            throw new BaseException("套餐为空");
        }
        return list;
    }

    /**
     * 根据套餐id查询菜品
     * @param id
     * @return
     */
    @Override
    public List<DishItemVO> dish(Long id) {
      //1.根据套餐id查询菜品
        List<DishItemVO> list = dishMapper.getBySetmealId2(id);
        if(list == null && list.size() == 0){
            throw new BaseException(MessageConstant.QUERY_DISH_FAILED);
        }
        return list;
    }
}
